qx.Class.define("lastfmbackup.test.model.RecentTracks", {
  
  extend : qx.dev.unit.TestCase,

  members : {
    
    testee : null,
    
    
    setUp : function()
    {
      this.testee = new lastfmbackup.model.RecentTracks();
    },
    
    testCount : function()
    {
      var expected = {
        "user"       : "Israfel11",
        "page"       : 1,
        "perPage"    : 128,
        "totalPages" : 3,
        "total"      : 267
      };
      
      this.testee.setUsername("Israfel11");
      this.testee.addListener("load", function(event)
      {
        this.resume(function()
        {
          this.assertEquals("count", event.getData().type);
          this.assertJsonEquals(expected, event.getData().data);
        }, this);
      }, this);
      this.testee.count();
      this.wait(10000);
    },
    
    testCountFail : function()
    {
      this.testee.setRetry(false);
      this.testee._baseUrl = "http://ws2.audioscrobbler.com/";
      
      this.testee.setUsername("Israfel11");
      this.testee.addListener("load", function(event)
      {
        this.resume(function()
        {
          this.fail("Fail expected");
        }, this);
      }, this);
      this.testee.addListener("fail", function(event)
      {
        this.resume(function()
        {
          this.assertEquals("count", event.getData().type);
          this.assertEquals("fail", event.getType());
          this.assertEquals(this.testee, event.getTarget());
        }, this);
      }, this);
      this.testee.count();
      this.wait();
    },
    
    testPage : function()
    {
      this.testee.setUsername("Israfel11");
      this.testee.addListener("load", function(event)
      {
        this.resume(function()
        {
          this.assertEquals("page", event.getData().type); 
          this.assertJsonEquals({
            "date"   : 1182241345,
            "track"  : {name : "Hooker With a Penis", mbid : "70c89dca-75e1-4516-b928-28d02d224499"},
            "album"  : {name : "Ænima", mbid : "b1b9bf98-86fa-4092-950f-1fb6744a25b4"},
            "artist" : {name : "Tool",  mbid : "22c94bce-544f-49ba-afdc-026beac4fd3e"}
          }, event.getData().data[0]);
          this.assertJsonEquals({
            "date"   : 1170006029,
            "track"  : {name : "Equinigma", mbid : null},
            "album"  : {name : null, mbid : null},
            "artist" : {name : "The Chronicles of Israfel", mbid : "fd63f57d-476e-4e63-97ef-90f92987b5e2"}
          }, event.getData().data[127]);
        }, this);
      }, this);
      this.testee.page(2);
      this.wait(10000);
    },
    
    testPageFail : function()
    {
      this.testee.setRetry(false);
      this.testee._baseUrl = "http://ws2.audioscrobbler.com/";
      
      this.testee.setUsername("Israfel11");
      this.testee.addListener("load", function(event)
      {
        this.resume(function()
        {
          this.fail("Fail expected");
        }, this);
      }, this);      
      this.testee.addListener("fail", function(event)
      {
        this.resume(function()
        {
          this.assertEquals("page", event.getData().type);
          this.assertEquals("fail", event.getType());
          this.assertEquals(this.testee, event.getTarget());
        }, this);
      }, this);
      this.testee.page(2);
      this.wait();
    }

  }
  
});